package com.platform.web.controller.base;
import java.util.List;

import com.platform.base.domain.MeterAnalysis;
import com.platform.base.domain.MeterType;
import com.platform.base.domain.ValveType;
import com.platform.base.service.IMeterAnalysisService;
import com.platform.base.service.IMeterTypeService;
import com.platform.common.annotation.Log;
import com.platform.common.core.controller.BaseController;
import com.platform.common.core.domain.AjaxResult;
import com.platform.common.core.page.TableDataInfo;
import com.platform.common.enums.BusinessType;
import com.platform.framework.util.ShiroUtils;
import org.springframework.stereotype.Controller;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * 热解析Controller
 * 
 * @author wangqi
 * @date 2021-04-25
 */
@Controller
@RequestMapping("/base/analysis")
public class MeterAnalysisController extends BaseController
{
    private String prefix = "base/analysis";

    @Autowired
    private IMeterAnalysisService meterAnalysisService;
    @Autowired
    private IMeterTypeService meterTypeService;

    @RequiresPermissions("base:analysis:view")
    @GetMapping(value = { "", "/{typeId}" })
    public String analysis(@PathVariable(value = "typeId", required = false) String typeId, ModelMap mmap)
    {
        List<MeterType> types = meterTypeService.list();
        mmap.put("types", types);
        if(typeId==null){
            typeId = "";
        }
        mmap.put("typeId", typeId);
        return prefix + "/analysis";
    }

    /**
     * 查询热解析列表
     */
    @RequiresPermissions("base:analysis:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MeterAnalysis meterAnalysis)
    {
        startPage();
        List<MeterAnalysis> list = meterAnalysisService.selectMeterAnalysisList(meterAnalysis);
        return getDataTable(list);
    }

    /**
     * 新增热解析
     */
    @GetMapping("/add/{typeId}")
    public String add(@PathVariable(value = "typeId") String typeId, ModelMap mmap)
    {
        List<MeterType> types = meterTypeService.list();
        mmap.put("types", types);
        mmap.put("typeId", typeId);
        return prefix + "/add";
    }

    /**
     * 新增保存热解析
     */
    @RequiresPermissions("base:analysis:add")
    @Log(title = "热解析", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MeterAnalysis meterAnalysis)
    {
        meterAnalysis.setCreateBy(ShiroUtils.getLoginName());
        return toAjax(meterAnalysisService.insertMeterAnalysis(meterAnalysis));
    }

    /**
     * 修改热解析
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap){
        MeterAnalysis meterAnalysis = meterAnalysisService.selectMeterAnalysisById(id);
        List<MeterType> types = meterTypeService.list();

        mmap.put("meterAnalysis", meterAnalysis);
        mmap.put("types", types);
        return prefix + "/edit";
    }

    /**
     * 修改保存热解析
     */
    @RequiresPermissions("base:analysis:edit")
    @Log(title = "热解析", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MeterAnalysis meterAnalysis)
    {
        meterAnalysis.setUpdateBy(ShiroUtils.getLoginName());
        return toAjax(meterAnalysisService.updateMeterAnalysis(meterAnalysis));
    }

    /**
     * 删除热解析
     */
    @RequiresPermissions("base:analysis:remove")
    @Log(title = "热解析", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(meterAnalysisService.deleteMeterAnalysisByIds(ids));
    }
}
